<?php

namespace Admin\Model;
use Think\Model;

class TeacherModel extends Model {


    public function getTeacherByWhere($where,$limit='') {
        return $this->where($where)->limit($limit)->select();
    }

    public function getCountByWhere($where) {
        return $this->where($where)->count();
    }


    public function getTeacherById($id) {
        return $this->find($id);
    }


    public function getTeacherName($id) {
        return $this->where('id = '.$id)->getField('name');
    }


    public function _add($data) {

        $map['teacher_id'] = $data['teacher_id'];
        $t = $this->where($map)->find();
        if (!empty($t)) return '100601';

        unset($map);
        $map['department_id'] = $data['department_id'];
        $map['name'] = $data['name'];
        $t = $this->where($map)->find();
        if (!empty($t)) return '100602';

        $flag = $this->add($data);
        if ($flag !== false) return '000000';
        return '111111';

    }


    public function _edit($data) {
        $map['name'] = $data['name'];
        $map['id'] = array('neq',$data['id']);
        $t = $this->where($map)->find();
        if (!empty($t)) return '100602';

        $flag = $this->save($data);
        if ($flag !== false) return '000000';
        return '111111';
    }



    public function _del($id) {
        $flag = $this->delete($id);
        if ($flag !== false) return '000000';
        return '111111';
    }

    /**
     * 教师登录方法
     *
     * @param $account
     * @param $password
     * @return mixed
     */
    public function login($account,$password) {
        $where['teacher_id'] = $account;
        $where['password'] = md5($password);
        return $this->where($where)->find();
    }

} 